package com.xhwl.centiotdata.suppliersystem.bailian;

import com.alibaba.fastjson.JSONObject;
import com.xhwl.common.dto.cent.iotdata.bailian.BaiLianResponseBean;
import com.xhwl.common.utils.CalendarUtil;
import com.xhwl.common.vo.cent.statistics.SaleThirdDataVO;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.*;

/**
 * Copyright (C),1998-2022, 兴海物联
 * FileName: PedestrianBaiLianMockUtil
 * Author: XuChang
 * Date: 2022/8/8 15:38
 * Description: 模拟数据类
 * History:
 */
public class BaiLianMockUtil {

    private static final String[] companyIds = {"0025", "0026", "0029"};

    public static JSONObject mockPedestrianTodayData(String dateStr) {
        Date date = new Date();
        try {
            date = CalendarUtil.getDate(CalendarUtil.DATE_FORMAT[1], dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Random random = new Random(date.getTime());
        String[] dayHours = getDayHours(date);
        List<BaiLianResponseBean.StoreFlowObject> storeFlow = new ArrayList<>();
        List<BaiLianResponseBean.DepartmentFlowObject> departmentFlow = new ArrayList<>();
        for (int i = 0; i < dayHours.length; i++) {
            String dayHour = dayHours[i];
            BaiLianResponseBean.StoreFlowObject storeFlowObject = new BaiLianResponseBean.StoreFlowObject();
            storeFlowObject.setTime(dayHour);
            storeFlowObject.setPedestrianInFlow(random.nextInt(1000));
            storeFlowObject.setPedestrianOutFlow(random.nextInt(1000));
            storeFlow.add(storeFlowObject);

            for (int j = 0; j < companyIds.length; j++) {
                int companyId = Integer.parseInt(companyIds[j]);
                BaiLianResponseBean.DepartmentFlowObject departmentFlowObject = new BaiLianResponseBean.DepartmentFlowObject();
                departmentFlowObject.setTime(dayHour);
                departmentFlowObject.setPedestrianInFlow(random.nextInt(100));
                departmentFlowObject.setPedestrianOutFlow(random.nextInt(100));
                departmentFlowObject.setDepartmentID(companyId + "");
                departmentFlow.add(departmentFlowObject);
            }
        }
        BaiLianResponseBean baiLianResponseBean = new BaiLianResponseBean();
        baiLianResponseBean.setStoreFlow(storeFlow);
        baiLianResponseBean.setDepartmentFlow(departmentFlow);
        return JSONObject.parseObject(JSONObject.toJSONString(baiLianResponseBean));
    }

    public static JSONObject mockPedestrianHistoryData(String dateStr) {
        Date date = new Date();
        try {
            date = CalendarUtil.getDate(CalendarUtil.DATE_FORMAT[1], dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Random random = new Random(date.getTime());

        List<BaiLianResponseBean.StoreFlowObject> storeFlow = new ArrayList<>();
        List<BaiLianResponseBean.DepartmentFlowObject> departmentFlow = new ArrayList<>();

        BaiLianResponseBean.StoreFlowObject storeFlowObject = new BaiLianResponseBean.StoreFlowObject();
        storeFlowObject.setPedestrianInFlow(random.nextInt(1000));
        storeFlowObject.setPedestrianOutFlow(random.nextInt(1000));
        storeFlowObject.setWanderTime(random.nextDouble());
        storeFlow.add(storeFlowObject);
        for (int j = 0; j < companyIds.length; j++) {
            int companyId = Integer.parseInt(companyIds[j]);
            BaiLianResponseBean.DepartmentFlowObject departmentFlowObject = new BaiLianResponseBean.DepartmentFlowObject();
            departmentFlowObject.setPedestrianInFlow(random.nextInt(100));
            departmentFlowObject.setPedestrianOutFlow(random.nextInt(100));
            departmentFlowObject.setDepartmentID(companyId + "");
            departmentFlowObject.setWanderTime(random.nextDouble());
            departmentFlow.add(departmentFlowObject);
        }
        BaiLianResponseBean baiLianResponseBean = new BaiLianResponseBean();
        baiLianResponseBean.setStoreFlow(storeFlow);
        baiLianResponseBean.setDepartmentFlow(departmentFlow);
        return JSONObject.parseObject(JSONObject.toJSONString(baiLianResponseBean));
    }

    public static String mockSaleData(String dateStr) {
        Date date = new Date();
        try {
            date = CalendarUtil.getDate(CalendarUtil.DATE_FORMAT[1], dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Random random = new Random(date.getTime());
        List<SaleThirdDataVO> list = new ArrayList<>();
        int[] types = {0, 1, 2};
        for (int i = 0; i < companyIds.length; i++) {
            for (int j = 0; j < types.length; j++) {
                SaleThirdDataVO saleThirdDataVO = new SaleThirdDataVO();
                saleThirdDataVO.setCount(new BigDecimal(random.nextInt(1000)));
                saleThirdDataVO.setSales(new BigDecimal(random.nextInt(10000) + random.nextDouble()));
                saleThirdDataVO.setSalesType(types[j] + "");
                list.add(saleThirdDataVO);
            }
        }
        return JSONObject.toJSONString(list);
    }

    private static String[] getDayHours(Date date) {
        //一天的数据是 10点到21点
        String[] hours = new String[11];
        Calendar instance = Calendar.getInstance();
        instance.setTime(date);
        instance.set(Calendar.MINUTE, 0);
        instance.set(Calendar.SECOND, 0);
        for (int i = 0; i < 11; i++) {
            instance.set(Calendar.HOUR_OF_DAY, i + 10);
            hours[i] = CalendarUtil.getDateStr(CalendarUtil.DATE_FORMAT[0], instance.getTime());
        }
        return hours;
    }
}
